package com.himiotech.core.project.model.base;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * Entity基类
 *
 * @author wuwenbin
 */
@Data
@Accessors(chain = true)
public class BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 创建者
     */
    @TableField(fill = FieldFill.INSERT)
    private String createBy;
    @TableField(fill = FieldFill.INSERT)
    private String createByName;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime gmtCreate;

    /**
     * 更新者
     */
    @TableField(fill = FieldFill.UPDATE)
    private String modifiedBy;
    @TableField(fill = FieldFill.UPDATE)
    private String modifiedByName;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.UPDATE)
    private LocalDateTime gmtModified;

    /**
     * 备注
     */
    private String remark;

    /**
     * 前端请求参数，包含 start~end between 的区间查询
     * 分别在属性名末尾加上 Start 或 End 即可
     */
    @TableField(exist = false)
    private Map<String, Object> searchParams;


    /**
     * sql 搜索值，如数据权限过滤使用此字段
     */
    @TableField(exist = false)
    private Map<String, Object> sqlSearchValue;


    public Map<String, Object> getSearchParams() {
        if (searchParams == null) {
            searchParams = new HashMap<>(2);
        }
        return searchParams;
    }

    public Map<String, Object> getSqlSearchValue() {
        if (searchParams == null) {
            searchParams = new HashMap<>(2);
        }
        return searchParams;
    }
}
